package com.example.testproj.utils;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @des:
 * @author: 芮勤
 * @date: 2019/6/11 09:53
 * @see {@link }
 */
public class ThreadUtil {
    private static ThreadUtil threadUtil;
    private ExecutorService cachedThreadPool;

    public static ThreadUtil getThreadUtil() {
        if (threadUtil==null){
            synchronized (ThreadUtil.class){
                if (threadUtil==null){
                    threadUtil=new ThreadUtil();
                }

            }
        }
        return threadUtil;
    }

    public ThreadUtil() {
        cachedThreadPool= Executors.newCachedThreadPool();
    }

    public Future submit(FutureTask futureTask){
        return cachedThreadPool.submit(futureTask);
    }

    public Future submit(Runnable runnable){
        return cachedThreadPool.submit(runnable);
    }
}
